package com.easyidea.its.domain.service.system.impl;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;

import com.easyidea.its.domain.model.system.Permission;
import com.easyidea.its.domain.repository.system.PermissionRepository;
import com.easyidea.its.domain.service.base.impl.BaseServiceImpl;
import com.easyidea.its.domain.service.system.PermissionService;

/**
 * 
 * @author hukn
 * 
 */
public class PermissionServiceImpl extends BaseServiceImpl<Permission>
		implements PermissionService {

	private PermissionRepository permissionRepository;

	@Override
	public PermissionRepository getBaseRepository() {
		return permissionRepository;
	}

	/**
	 * @return the permissionRepository
	 */
	public PermissionRepository getPermissionRepository() {
		return permissionRepository;
	}

	/**
	 * @param permissionRepository
	 *            the permissionRepository to set
	 */
	public void setPermissionRepository(
			PermissionRepository permissionRepository) {
		this.permissionRepository = permissionRepository;
	}

	public List<Permission> getAllPerssionsByParentId(Integer parentId) {
		// TODO Auto-generated method stub
		return permissionRepository.getAllPerssionsByParentId(parentId);
	}

	public Permission getPermissionById(Integer id) {
		return this.permissionRepository.getBeanById(id);
	}

	public List<String> getAllPermissionUrls() {
		List<String> userPermissionUrlList = new ArrayList<String>(0);
		Collection<Permission> userPermissions = permissionRepository
				.getAllPermissions();
		if (userPermissions == null) {
			return userPermissionUrlList;
		} else {
			for (Iterator<Permission> permiter = userPermissions.iterator(); permiter
					.hasNext();) {
				Permission perm = permiter.next();
				// if (!perm.isDeleted()) {
				userPermissionUrlList.addAll(perm.getUrlList());
				// }
			}
		}
		return userPermissionUrlList;
	}

}
